import 'package:dmz/base/controller/base_controller.dart';
import 'package:dmz/business/home/controller/home_main_controller.dart';
import 'package:dmz/business/home/model/moto_model.dart';
import 'package:dmz/request/apis.dart';
import 'package:dmz/request/request_client.dart';

import 'package:get/get.dart';

import '../../../routers/routers.dart';
import '../../../utils/customize_loding.dart';
import '../widgets/scan_result_widget.dart';

class CodeScanResultRontroller extends BaseController {
  late String snCode;
  final deviceDatas = RxList<MotoModel>([]);

  @override
  void loadNet() {}

  @override
  void onHidden() {}

  @override
  void onReady() {
    super.onReady();
    //接收参数
    if (Get.arguments != null) snCode = Get.arguments as String;
    getDiveceInfor();
  }

  /// 获取车辆信息
  void getDiveceInfor() {
    RequestClient()
        .post<MotoModel>(APIS.getMoto, data: {'sn_code': snCode}).then((value) {
      if (value != null) deviceDatas.add(value);
    });
  }

  /// 绑定车辆
  void bindMoto() {
    RequestClient().post<MotoModel>(
      APIS.bindMoto,
      data: {'sn_code': snCode},
    ).then((value) {
      Get.find<HomePageController>().dontGetVison = true;
      Get.find<HomePageController>().getMotolist();
      EMILoding.showBottomWindow(const CodeScanResult(), close: () {
        Get.find<HomePageController>().dontGetVison = false;
        Get.until((route) => route.settings.name == RouteGet.main);
        Future.delayed(const Duration(seconds: 1), () {
          Get.find<HomePageController>().getVersion(snCode);
        });
      });
    });
  }

  /// 链接车辆蓝牙
  void showScuessWindow() {}
}

class CodeScanResultBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut(() => CodeScanResultRontroller());
  }
}
